<?php
    class WZ_StoreObject 
    {
        public function save()
        {
            $s = \WZ_Store::session();
            $store = $this->storeName;
            $vars = get_object_vars($this);
            foreach ($vars as $key => $value) {
                $s->$store->$key = $value;
            }
        }
        
        public function __call($method, $args)
        {
            $meth = substr($method, 0, 3);
            if ($meth == 'get') {
                $var = strtolower(substr($method, 3));
                return self::get($var);
            } elseif ($meth == 'set') {
                $var = strtolower(substr($method, 3));
                return self::set($var, $args[0]);
            }
        }
        
        public function __set($key, $value)
        {
            $this->$key = $value;
        }
        
        public function __get($key)
        {
            if (isset($this->$key)) {
                return $this->$key;
            }
            return null;
        }
        
        public function delete()
        {
            $s = \WZ_Store::session();
            $store = $this->storeName;
            $s->$store = null;
        }
        
        public function set($key, $value)
        {
            $this->$key = $value;
        }
        
        public function get($key)
        {
            if (isset($this->$key)) {
                return $this->$key;
            }
            return null;
        }
    }